//
//  MainViewController.swift
//  SinaWeibo
//
//  Created by 梁楠 on 16/1/11.
//  Copyright © 2016年 QQ主流框架. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    //MARK: 按钮的监听事件
    //私有函数加 @objc private
    @objc private func plusBtnDidlick () {
    
        //打印当前函数
        print(__FUNCTION__)
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //系统的tabbar是只读属性,UITabBar类型
        let mainTabbar = MainTabbar()
        
        setValue(mainTabbar, forKey: "tabBar")
        //ClassForCoder打印当前类
//        print(tabBar.classForCoder)
//        print(mainTabbar.subviews)
        
        //传递方法可以直接传字符串,省去Selector( )
        mainTabbar.plasBtn.addTarget(self, action: Selector("plusBtnDidlick"), forControlEvents: UIControlEvents.TouchUpInside)
        
        addChildViewControllers()
        
        print(mainTabbar.subviews.count)
    }
    
    func addChildViewControllers() {
        
        //首页
        addChildViewController(HomeTableViewController(), imageName: "tabbar_home", title: "首页")
        //消息
        addChildViewController(MessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        //发现
        addChildViewController(DiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        //我
        addChildViewController(ProfileTableViewController(), imageName: "tabbar_profile", title: "我")
        
    }
    
    func addChildViewController(vc : UIViewController , imageName : String , title : String) {
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
//        self.tabBar.tintColor = UIColor.orangeColor()
        
//        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//        
//        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        /*
        vc.tabBarItem.titleTextAttributesForState(UIControlState.Selected)
        */
        
//        home.tabBarItem.title = "首页"
//        
//        home.navigationItem.title = "首页"
        
        vc.title = title
        
        let nav = UINavigationController(rootViewController: vc)
        
        addChildViewController(nav)
        
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

}
